package com.yuanfeng.job.job;

import com.yuanfeng.commoms.vo.activity.EffectiveActivityVO;
import com.yuanfeng.job.mapper.SpinwinActivityMapper;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @ClassName UpdateSpinwinActivityStatusJob
 * @Description
 * @Author hyq
 * @Date 2023/9/5 13:57
 * @Version 1.0
 **/

public class UpdateSpinwinActivityStatusJob implements BaseJob{

    private static final Logger LOG = LoggerFactory.getLogger(UpdateSpinwinActivityStatusJob.class);

    @Autowired
    private SpinwinActivityMapper spinwinActivityMapper;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        LOG.info("更新大转盘活动状态");
        // 查询过期活动
        List<Integer> activityIdList = spinwinActivityMapper.selectExpireActivity();

        if (!CollectionUtils.isEmpty(activityIdList)) {
            spinwinActivityMapper.updateLuckyDraw(activityIdList);
            spinwinActivityMapper.updateActivityStatus(activityIdList);
        }

        //查询可用活动
        EffectiveActivityVO activity = spinwinActivityMapper.selectEffectiveActivity();

        if (null != activity) {
            spinwinActivityMapper.updateDailyLottery(activity);
        }
    }
}
